package com.five.sso.controller;

import com.five.core.result.Result;
import com.five.sso.service.SendMsgService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/smg")
public class SendMsgController {

    @Resource
    private SendMsgService sendMsgService;
    @GetMapping("/register/{phone}")
    public Result send(@PathVariable("phone") String phone){
        if(!phone.matches("^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$")){
            return Result.buildFail(50003,"手机号码不合法!");
        }
        sendMsgService.sendRegisterMsg(phone);
        return Result.buildSuccess();
    }

    @GetMapping("/login/{phone}")
    public Result login(@PathVariable("phone") String phone){
        if(!phone.matches("^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$")){
            return Result.buildFail(50003,"手机号码不合法!");
        }
        sendMsgService.sendLoginMsg(phone);
        return Result.buildSuccess();
    }

    @GetMapping("/oneLogin/{phone}")
    public Result oneLogin(@PathVariable("phone") String phone){
        if(!phone.matches("^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$")){
            return Result.buildFail(50003,"手机号码不合法!");
        }
        sendMsgService.sendOneLoingMsg(phone);
        return Result.buildSuccess();
    }

}
